global data ""  // path for source data
global temp ""  // path for intermediary data
global final ""  // path for final replication sample
global tables ""  // path for exporting tables
global figures ""  // path for exporting figures

/*------------------------------------------------------------------------------
This do file carries out the analysis as reported in the tables and figures in 
the main text and Supplementary Information. The code follows the order of 
tables that appear in the paper with a few exceptions (Figure 2 is with 
Table S6; Figures 1, S1-S2 and Table S3 are in Famine-intensity.do).
------------------------------------------------------------------------------*/

********************************************************************************
// Table 1
********************************************************************************

use "$final/Census05_sample.dta", clear

global sample birthyr <=1961 
global options cluster(uid2000)
global btopt bootstrap, force reps(100) seed(1)
global outfile "$tables/Table1_entrepreneur.xls"

* all
local dv: var label private_boss1
reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample, ///
	$options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", replace  bdec(3) sdec(3) ctitle("all: `dv'") ///
	nor2 nocons addstat(Counties, e(N_clust), Outcome mean, $avg ) ///
	keep(rltv_death_rate_n_1990) addtext(region FE, Yes) label ///
	addnote(Robust s.e. clustered at county level) 

local dv: var label private_boss2
reg private_boss2 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample , ///
	$options vce($btopt)
su private_boss2 if e(sample)
global avg : display %5.3f r(mean)
outreg2  using "$outfile", append  bdec(3) sdec(3) ctitle("all: `dv'") nor2 ///
	nocons addstat(Counties, e(N_clust), Outcome mean, $avg ) ///
	keep(rltv_death_rate_n_1990) addtext(region FE, Yes) label 

* female
local dv: var label private_boss1
reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample ///
	& male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2  using "$outfile", append  bdec(3) sdec(3) ctitle("female: `dv'") nor2 ///
	nocons addstat(Counties, e(N_clust), Outcome mean, $avg ) ///
	keep(rltv_death_rate_n_1990) label addtext(region FE, Yes)

local dv: var label private_boss2
reg private_boss2 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample & ///
	male==0, $options vce($btopt)
su private_boss2 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append  bdec(3) sdec(3) ctitle("female: `dv'") nor2 ///
	nocons addstat(Counties, e(N_clust), Outcome mean, $avg ) ///
	keep(rltv_death_rate_n_1990) label addtext(region FE, Yes) 

* male
local dv: var label private_boss1
reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample & ///
	male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append  bdec(3) sdec(3) ctitle("male: `dv'") nor2 ///
	nocons addstat(Counties, e(N_clust), Outcome mean, $avg ) ///
	keep(rltv_death_rate_n_1990) label addtext(region FE, Yes)  

local dv: var label private_boss2
reg private_boss2 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample & ///
	male==1, $options vce($btopt)
su private_boss2 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append  bdec(3) sdec(3) ctitle("male: `dv'") nor2 ///
	nocons addstat(Counties, e(N_clust), Outcome mean, $avg ) ///
	keep(rltv_death_rate_n_1990) label addtext(region FE, Yes)


gen income_ln = ln(income)
global outfile "$tables/Table1_income.xls"

* all
local dv: var label private_boss1
reg income_ln rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample & ///
	private_boss1==1, $options vce($btopt)
su income_ln if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", replace bdec(3) sdec(3) ctitle("all: income of `dv'") ///
	nor2 nocons addstat(Counties, e(N_clust), Outcome mean, $avg ) ///
	keep(rltv_death_rate_n_1990) addnote(Robust s.e. clustered at county level) ///
	addtext(region FE, Yes) label

* female
local dv: var label private_boss1
reg income_ln rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample & ///
	male==0 & private_boss1==1, $options vce($btopt)
su income_ln if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) ctitle("female: income of `dv'") ///
	nor2 nocons addtext(region FE, Yes) keep(rltv_death_rate_n_1990) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg ) 

* male
local dv: var label private_boss1
reg income_ln rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample & ///
	male==1 & private_boss1==1, $options vce($btopt)
su income_ln if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) ctitle("male: income of `dv'") ///
	nor2 nocons addtext(region FE, Yes) keep(rltv_death_rate_n_1990) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg )  



********************************************************************************
// Table 2
********************************************************************************
use "$final\chfs13_sample.dta",clear
keep if birthyr<1962.

global iv="rltv_death_rate_n_1990"
global dep="busi_owner"
global indep="risk_loving"
global ind="age minority primary highschool college urban health"
global weight="[pweight=swgt]"
global clu="vce(bootstrap, force rep(100) seed(1)) cluster(cityid)"

egen mis2=rowmiss($dep $iv $ind $indep)
gen samp2=.

replace samp2=(mis2==0&respond==1)

global con="male $ind"

foreach dep of varlist $indep $dep $iv {
qui sum `dep' if samp2==1,detail
scalar ave_`dep'=round(r(mean),.001)
}

//both genders
reg $indep $iv $con $weight if samp2==1, $clu
estadd local profe "Yes"
estadd local birth "Yes"
estadd local con "Yes"
estadd scalar cou=e(N_clust)
estadd scalar ave=ave_$indep
est store risk
reg $dep $iv $con $weight if samp2==1, $clu
estadd local profe "Yes"
estadd local birth "Yes"
estadd local con "Yes"
estadd scalar cou=e(N_clust)
estadd scalar ave=ave_$dep
est store busi1
xi: reg $dep $iv $indep $con  $weight if samp2==1,  $clu
estadd local profe "Yes"
estadd local birth "Yes"
estadd local con "Yes"
estadd scalar cou=e(N_clust)
estadd scalar ave=ave_$dep
est store busi2

*spouse
replace samp2=(mis==0&a2001==2)
qui sum $dep if samp2==1,detail
scalar ave_$dep =round(r(mean),.001)

xi: reg $dep $iv risk_spouse $con $weight if samp2==1,  $clu
estadd local profe "Yes"
estadd local birth "Yes"
estadd local con "Yes"
estadd scalar cou=e(N_clust)
estadd scalar ave=ave_$dep
est store busi_spouse

*
//by genders
forvalue i=0(1)1{
replace samp2=(mis2==0&respond==1&male==`i')
global con="$ind $fe"

foreach dep of varlist $indep $dep $iv{
qui sum `dep' if samp2==1,detail
scalar ave_`dep'=round(r(mean),.001)
}
reg $indep $iv $con $weight if samp2==1, $clu
estadd local profe "Yes"
estadd local birth "Yes"
estadd local con "Yes"
estadd scalar cou=e(N_clust)
estadd scalar ave=ave_$indep
est store risk_`i'
reg $dep $iv $con $weight if samp2==1, $clu
estadd local profe "Yes"
estadd local birth "Yes"
estadd local con "Yes"
estadd scalar cou=e(N_clust)
estadd scalar ave=ave_$dep
est store busi1_`i'
xi: reg $dep $iv $indep $con $weight if samp2==1,  $clu
estadd local profe "Yes"
estadd local birth "Yes"
estadd local con "Yes"
estadd scalar cou=e(N_clust)
estadd scalar ave=ave_$dep
est store busi2_`i'

*spouse
replace samp2=(mis==0&a2001==2&male==`i')
qui sum $dep if samp2==1,detail
scalar ave_$dep =round(r(mean),.001)

xi: reg $dep $iv risk_spouse $con $weight if samp2==1,  $clu
estadd local profe "Yes"
estadd local birth "Yes"
estadd local con "Yes"
estadd scalar cou=e(N_clust)
estadd scalar ave=ave_$dep
est store busi_spouse`i'
}

esttab busi1 risk busi2 busi_spouse  , ///
keep($iv $indep risk_spouse )  order($iv $indep )  star(* 0.10 ** 0.05 *** 0.01) stats(con N cou ave, ///
label("Individual controls" "Observations" "# counties" "Mean") fmt(0 0 0 3 3 3)) se(3)

esttab busi1_0 risk_0 busi2_0 busi_spouse0 , ///
keep($iv $indep risk_spouse )  order($iv $indep )  star(* 0.10 ** 0.05 *** 0.01) stats(con N cou ave, ///
label("Individual controls" "Observations" "# counties" "Mean") fmt(0 0 0 3 3 3))  se(3)

esttab busi1_1 risk_1 busi2_1 busi_spouse1  , ///
keep($iv $indep risk_spouse )  order($iv $indep )  star(* 0.10 ** 0.05 *** 0.01) stats(con N cou ave, ///
label("Individual controls" "Observations" "# counties" "Mean") fmt(0 0 0 3 3 3))  se(3)

esttab busi1 risk busi2 busi_spouse busi1_0 risk_0 busi2_0 busi_spouse0 busi1_1 risk_1 busi2_1 busi_spouse1   ///
using "$tables\Table2_busi_owner.csv", keep($iv $indep risk_spouse) order($iv $indep male $con) replace se b(3) ///
mtitles("Business owner " "Risk tolerance" "Business owner " "Business owner " "Business owner (Female) " "Risk tolerance (Female) " ///
"Business owner (Female) " "Business owner (Female) " "Business owner (Male) " "Risk tolerance (Male)" "Business owner (Male)" "Business owner (Male)") ///
depvars star(* 0.10 ** 0.05 *** 0.01) nogaps label title("") stats(con N cou ave, ///
label("Individual controls" "Observations" "# counties" "Mean") fmt(0 0 0 3 3 3))


**************************************************
*** Table S2 Thermal agricultural productivity ***
**************************************************
use "$final/Weather_sample_1.dta", clear
global outfile "$tables/TableS2_thermal_serialcorr_1.xls"
reg degree1_cur degree1_lag1 , cl(stationid)
unique stationid if e(sample)
global station = r(sum)
su degree1_cur
global avg : display %5.3f r(mean)
outreg2 using "$outfile", replace ctitle("Previous year") label nocon ///
	addtext("Station fixed effects", "No", "Stations" , $station ) ///
	addstat(Outcome mean, $avg ) ///
	title("Agricultural thermal productivity: serial correlation") ///
	addnote("Sample: All weather stations with full coverage during growing season, year 1951-70. Dependent variable: Current year agriculture thermal productivity. Robust s.e. clustered at station level")

reg degree1_cur degree1_lag1 degree1_lag2, cl(stationid)
unique stationid if e(sample)
global station = r(sum)
su degree1_cur
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append ctitle("Previous two years") label nocon ///
	addstat(Outcome mean, $avg ) ///
	addtext("Station fixed effects", "No", "Stations" , $station )

areg degree1_cur degree1_lag1, absorb(stationid) cl(stationid)
unique stationid if e(sample)
global station = r(sum)
su degree1_cur
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append ctitle("Previous year") label nocon ///
	addstat(Outcome mean, $avg ) ///
	addtext("Station fixed effects", "Yes", "Stations" , $station )

areg degree1_cur degree1_lag1 degree1_lag2, absorb(stationid) cl(stationid)
unique stationid if e(sample)
global station = r(sum)
su degree1_cur
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append ctitle("Previous two years") label nocon ///
	addstat(Outcome mean, $avg ) ///
	addtext("Station fixed effects", "Yes", "Stations" , $station )


use "$final/Weather_sample_2.dta", clear
global outfile "$tables/TableS2_thermal_serialcorr_2.xls"
reg avg_degree_diff avg_degree0
su avg_degree_diff if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile" , replace label nocon addstat(Outcome mean, $avg)


******************************************************************
*** Table S4 Famine severity and entrepreneurship - Robustness ***
******************************************************************

use "$final/Census05_sample.dta", clear

global sample birthyr<=1961
global options cluster(uid2000) 
global btopt bootstrap, force reps(100) seed(1)
global control1 race sex age rural eduyr
global control2 govt_exp
global control3 agri_93

* All

global outfile $tables/TableS4_robust_all.xls

reg private_boss1 rltv_death_rate_n_1990 $control1 i.region6 [pw = power_2] if ///
	$sample, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", replace bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Individual controls")

reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample & ///
	birthyr >= 1945 , $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", replace bdec(3) sdec(3) ctitle("Below 60") nor2 ///
	keep(rltv_death_rate_n_1990) nocons addtext(region FE, Yes) ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ///
	addnote(Robust s.e. clustered at county level) 

reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample & ///
	birthyr >= 1950 , $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) ctitle("Below 55") nor2 ///
	keep(rltv_death_rate_n_1990) nocons addtext(region FE, Yes) ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) label

reg private_boss1 rltv_death_rate_n_1990 $control2 i.region6 [pw = power_2] if ///
	$sample, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Government expenditure")

reg private_boss1 rltv_death_rate_n_1990 $control3 i.region6 [pw = power_2] if ///
	$sample, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Agricultural productivity")
	
reg private_boss1 rltv_death_rate_n_1990 migrate_in_r i.region6 [pw = power_2] ///
	if $sample, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", replace bdec(3) sdec(3) keep(rltv_death_rate_n_1990) ///
	nor2 nocons addtext(region FE, Yes) /// 
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ctitle("In-migration")
	
reg private_boss1 rltv_death_rate_n_1990 popn i.region6 [pw = power_2] if ///
	$sample, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) /// 
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ctitle("Population")

reg private_boss1 rltv_death_rate_n_1990 gdpc i.region6 [pw = power_2] if ///
	$sample, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) /// 
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ctitle("GDP per capita")
	
reg private_boss1 rltv_death_rate_n_1990 priv_large i.region6 [pw = power_2] ///
	if $sample, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) /// 
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ctitle("Share of large enterprises")

reg private_boss1 rltv_death_rate_n_1990 ind1_r ind2_r i.region6 [pw = power_2] ///
	if $sample, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) /// 
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ctitle("Shares of primary and secondary industries")

reg private_boss1 rltv_death_rate_n_1990 migrate_in_r priv_large popn gdpc ///
	ind1_r ind2_r i.region6 [pw = power_2] if $sample, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) /// 
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ctitle("(f)-(j) controlled")

reg private_boss1 rltv_death_rate_n_1990_q i.region6 [pw = power_2] if $sample, ///
	$options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990_q) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Quadratic projection")

reg private_boss1 rltv_death_rate_n_1990_e i.region6 [pw = power_2] if $sample, ///
	$options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990_e) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Exponential projection")

reg private_boss1 rltv_death_rate_n_2000 i.region6 [pw = power_2] if $sample, ///
	$options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_2000) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Projection using 2000 census")

reg private_boss1 rltv_death_rate_n_9000 i.region6 [pw = power_2] if $sample, ///
	$options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_9000) ///
	nor2 nocons addtext(region FE, Yes) label  ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Projection using 2000+1990 censuses")
	
local dv: var label private_boss1
reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample , $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", replace  bdec(3) sdec(3) ctitle("Cutoff at 1958") nor2 ///
	keep(rltv_death_rate_n_1990) nocons addtext(region FE, Yes) ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) label 
	
reg private_boss1 rltv_death_rate_n_1990_mono i.region6 [pw = power_2] if ///
	$sample, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990_mono) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Alternative thermal formula")

reg private_boss1 rltv_death_rate_n_1990_w i.region6 [pw = power_2] if $sample, ///
	$options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990_w) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Weighted average of three weather stations")

reg private_boss1 rltv_death_rate_n_1990_a i.region6 [pw = power_2] if $sample, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990_a) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("All month's degree")
	
local dv: var label private_boss1
reg private_boss1 rltv_est_deathm_n_1990 i.region6 [pw = power_2] if $sample , ///
	$options vce($btopt)
su private_boss1 if e(sample)
global avg r(mean)
outreg2 using "$outfile", replace bdec(3) sdec(3) ctitle("region-specifc growing season") ///
	nor2 nocons keep(rltv_est_deathm_n_1990) addtext(region FE, Yes) ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ///
	addnote(Robust s.e. clustered at county level) 

probit private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample, ///
	$options vce($btopt)
global counties = e(N_clust)
su private_boss1 if e(sample)
global p_mean = r(mean)
margins, dydx(rltv_death_rate_n_1990) predict(pr) atmeans post
estimates store mymargins
outreg2 mymargins using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, $counties, Outcome mean, $p_mean) ctitle("Probit")

reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample, ///
	cluster(prov) vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Std error clustered by province")

reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample, cluster(region) vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Std error clustered by prefecture")

preserve 
keep if $sample & !mi(rltv_death_rate_n_1990)
collapse private_boss1 rural eduyr ,by(uid2000 rltv_death_rate_n_1990 region6 _ID)

spmat contiguity cobjn using "$data/China_coord.dta", id(_ID) normalize(minmax)	

xi: spreg ml private_boss1 rltv_death_rate_n_1990 i.region6, id(_ID) dlmat(cobjn) elmat(cobjn)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Outcome mean, $avg) ctitle("Spatial Correlation")
restore


* Female

global outfile $tables/TableS4_robust_female.xls

reg private_boss1 rltv_death_rate_n_1990 $control1 i.region6 [pw = power_2] if ///
	$sample & male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", replace bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Individual controls")
	
reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample & ///
	birthyr >= 1945 & male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) ctitle("Below 60") nor2 ///
	keep(rltv_death_rate_n_1990) addstat(Counties, e(N_clust), Outcome mean, ///
	$avg) nocons addtext(region FE, Yes) label  

reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample & ///
	birthyr >= 1950 & male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) ctitle("Below 55") nor2 ///
	keep(rltv_death_rate_n_1990) addstat(Counties, e(N_clust), Outcome mean, ///
	$avg) nocons addtext(region FE, Yes) label

reg private_boss1 rltv_death_rate_n_1990 $control2 i.region6 [pw = power_2] ///
	if $sample & male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Government expenditure")

reg private_boss1 rltv_death_rate_n_1990 $control3 i.region6 [pw = power_2] ///
	if $sample & male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Agricultural productivity")
	
reg private_boss1 rltv_death_rate_n_1990 migrate_in_r i.region6 [pw = power_2] ///
	if $sample & male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", replace bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) /// 
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ctitle("In-migration")


reg private_boss1 rltv_death_rate_n_1990 popn i.region6 [pw = power_2] if ///
	$sample & male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) /// 
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ctitle("Population")

reg private_boss1 rltv_death_rate_n_1990 gdpc i.region6 [pw = power_2] if ///
	$sample & male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) /// 
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ctitle("GDP per capita")

reg private_boss1 rltv_death_rate_n_1990 ind1_r ind2_r i.region6 [pw = power_2] ///
	if $sample & male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) /// 
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ctitle("Shares of primary and secondary industries")

reg private_boss1 rltv_death_rate_n_1990 priv_large i.region6 [pw = power_2] ///
	if $sample & male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) /// 
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ctitle("Share of large enterprises")
	
reg private_boss1 rltv_death_rate_n_1990 migrate_in_r priv_large popn gdpc ///
	ind1_r ind2_r i.region6 [pw = power_2] if $sample & male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) /// 
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ctitle("(f)-(j) controlled")

reg private_boss1 rltv_death_rate_n_1990_q i.region6 [pw = power_2] if $sample ///
	& male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990_q) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Quadratic projection")

reg private_boss1 rltv_death_rate_n_1990_e i.region6 [pw = power_2] if $sample///
	& male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990_e) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Exponential projection")

reg private_boss1 rltv_death_rate_n_2000 i.region6 [pw = power_2] if $sample ///
	& male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_2000) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Projection using 2000 census")

reg private_boss1 rltv_death_rate_n_9000 i.region6 [pw = power_2] if $sample ///
	& male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_9000) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Projection using 2000+1990 censuses")
	
local dv: var label private_boss1
reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2]  if $sample & ///
	male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append  bdec(3) sdec(3) ctitle("Cutoff at 1958") nor2 ///
	keep(rltv_death_rate_n_1990) addstat(Counties, e(N_clust), Outcome mean, ///
	$avg) nocons addtext(region FE, Yes) label  
	
reg private_boss1 rltv_death_rate_n_1990_mono i.region6 [pw = power_2] if $sample ///
	& male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990_mono) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Alternative thermal formula")

reg private_boss1 rltv_death_rate_n_1990_w i.region6 [pw = power_2] if $sample ///
	& male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990_w) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Weighted average of three weather stations")

reg private_boss1 rltv_death_rate_n_1990_a i.region6 [pw = power_2] if $sample ///
	& male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990_a) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("All month's degree")

local dv: var label private_boss1
reg private_boss1 rltv_est_deathm_n_1990 i.region6 [pw = power_2] if $sample & ///
	male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) ctitle("region-specifc growing season") ///
	nor2 nocons keep(rltv_est_deathm_n_1990) addtext(region FE, Yes) ///
	addstat(Counties, e(N_clust), Outcome mean, $avg)  label  

probit private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample ///
	& male==0, $options vce($btopt)
global counties = e(N_clust)
su private_boss1 if e(sample)
global p_mean = r(mean)
margins, dydx(rltv_death_rate_n_1990) predict(pr) atmeans post
estimates store mymargins
outreg2 mymargins using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, $counties, Outcome mean, $p_mean) ctitle("Probit")

reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample & ///
	male==0, cluster(prov) vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Std error clustered by province")

reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample & ///
	male==0, cluster(region) vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Std error clustered by prefecture")

preserve 
keep if $sample & male==0 & !mi(rltv_death_rate_n_1990) 
collapse private_boss1 rural eduyr ,by(uid2000 rltv_death_rate_n_1990 region6 _ID)

spmat contiguity cobjf using "$data/China_coord.dta", id(_ID) normalize(minmax)	

xi: spreg ml private_boss1 rltv_death_rate_n_1990 i.region6, id(_ID) dlmat(cobjf) elmat(cobjf) 
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Outcome mean, $avg) ctitle("Spatial Correlation")
restore

* Male

global outfile $tables/TableS4_robust_male.xls

reg private_boss1 rltv_death_rate_n_1990 $control1 i.region6 [pw = power_2] if ///
	$sample & male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", replace bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Individual controls")

reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample ///
	& birthyr >= 1945 & male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) ctitle("Below 60") nor2 ///
	keep(rltv_death_rate_n_1990) addstat(Counties, e(N_clust), Outcome mean, ///
	$avg ) nocons addtext(region FE, Yes) label  

reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample ///
	& birthyr >= 1950 & male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) ctitle("Below 55") nor2 ///
	keep(rltv_death_rate_n_1990) addstat(Counties, e(N_clust), Outcome mean, ///
	$avg ) nocons addtext(region FE, Yes) label 
	
reg private_boss1 rltv_death_rate_n_1990 $control2 i.region6 [pw = power_2] if ///
	$sample & male==1, $options
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Government expenditure")

reg private_boss1 rltv_death_rate_n_1990 $control3 i.region6 [pw = power_2] if ///
	$sample & male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Agricultural productivity")

reg private_boss1 rltv_death_rate_n_1990 migrate_in_r i.region6 [pw = power_2] ///
	if $sample & male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", replace bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) /// 
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ctitle("In-migration")
	
reg private_boss1 rltv_death_rate_n_1990 popn i.region6 [pw = power_2] if ///
	$sample & male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) /// 
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ctitle("Population")

reg private_boss1 rltv_death_rate_n_1990 gdpc i.region6 [pw = power_2] if ///
	$sample & male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) /// 
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ctitle("GDP per capita")

reg private_boss1 rltv_death_rate_n_1990 ind1_r ind2_r i.region6 [pw = power_2] ///
	if $sample & male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) /// 
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ctitle("Shares of primary and secondary industries")

reg private_boss1 rltv_death_rate_n_1990 priv_large i.region6 [pw = power_2] ///
	if $sample & male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) /// 
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ctitle("Share of large enterprises")
	
reg private_boss1 rltv_death_rate_n_1990 migrate_in_r priv_large popn gdpc ///
	ind1_r ind2_r i.region6 [pw = power_2] if $sample & male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) /// 
	nor2 nocons addtext(region FE, Yes) /// 
	addstat(Counties, e(N_clust), Outcome mean, $avg) label ctitle("(f)-(j) controlled")

reg private_boss1 rltv_death_rate_n_1990_q i.region6 [pw = power_2] if $sample ///
	& male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990_q) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Quadratic projection")

reg private_boss1 rltv_death_rate_n_1990_e i.region6 [pw = power_2] if $sample ///
	& male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990_e) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Exponential projection")

reg private_boss1 rltv_death_rate_n_2000 i.region6 [pw = power_2] if $sample ///
	& male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_2000) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Projection using 2000 census")

reg private_boss1 rltv_death_rate_n_9000 i.region6 [pw = power_2] if $sample ///
	& male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_9000) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Projection using 2000+1990 censuses")

local dv: var label private_boss1
reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample & ///
	male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append  bdec(3) sdec(3) ctitle("Cutoff at 1958") nor2 ///
	keep(rltv_death_rate_n_1990) addstat(Counties, e(N_clust), Outcome mean, ///
	$avg ) nocons addtext(region FE, Yes) label  
	
reg private_boss1 rltv_death_rate_n_1990_mono i.region6 [pw = power_2] if ///
	$sample & male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990_mono) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Alternative thermal formula")

reg private_boss1 rltv_death_rate_n_1990_w i.region6 [pw = power_2] if $sample ///
	& male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990_w) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Weighted average of three weather stations")

reg private_boss1 rltv_death_rate_n_1990_a i.region6 [pw = power_2] if $sample ///
	& male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990_a) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("All month's degree")

local dv: var label private_boss1
reg private_boss1 rltv_est_deathm_n_1990 i.region6 [pw = power_2] if $sample ///
	& male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) ctitle("region-specifc growing season") ///
	nor2 nocons keep(rltv_est_deathm_n_1990) addtext(region FE, Yes) ///
	addstat(Counties, e(N_clust), Outcome mean, $avg)  label  

probit private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample ///
	& male==1, $options vce($btopt)
global counties = e(N_clust)
su private_boss1 if e(sample)
global p_mean = r(mean)
margins, dydx(rltv_death_rate_n_1990) predict(pr) atmeans post
estimates store mymargins
outreg2 mymargins using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, $counties, Outcome mean, $p_mean) ctitle("Probit")

reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample & ///
	male==1, cluster(prov) vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Std error clustered by province")

reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if $sample & ///
	male==1, cluster(region) vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("Std error clustered by prefecture")

preserve 
keep if $sample & male==1 & !mi(rltv_death_rate_n_1990)
collapse private_boss1 rural eduyr , by(uid2000 rltv_death_rate_n_1990 region6 _ID)

spmat contiguity cobjm using "$data/China_coord.dta", id(_ID) normalize(minmax)	

xi: spreg ml private_boss1 rltv_death_rate_n_1990 i.region6, id(_ID) dlmat(cobjm) elmat(cobjm) 
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) keep(rltv_death_rate_n_1990) ///
	nor2 nocons addtext(region FE, Yes) label ///
	addstat(Outcome mean, $avg) ctitle("Spatial Correlation")
restore
	
**********************************************************
*** Table S5 Heterogeneous effects by famine intensity ***
**********************************************************

global sample birthyr <= 1961 
global options cluster(uid2000)
global btopt bootstrap, force reps(100) seed(1)
global outfile $tables/TableS5_heterogeneous.xls

* By quartile

reg private_boss1 rltv_death_rate_n_1990 famine_q2 famine_q3 famine_q4 ///
	i.region6 [pw = power_2] if $sample, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", replace  bdec(3) sdec(3) ctitle("all") nor2 nocons ///
	addstat(Counties, e(N_clust), Outcome mean, $avg ) ///
	keep(rltv_death_rate_n_1990 famine_q2 famine_q3 famine_q4) ///
	addtext(region FE, Yes)	label

reg private_boss1 rltv_death_rate_n_1990 famine_q2 famine_q3 famine_q4 ///
	i.region6 [pw = power_2] if $sample & male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2  using "$outfile", append  bdec(3) sdec(3) ctitle("female") nor2 nocons ///
	addstat(Counties, e(N_clust), Outcome mean, $avg ) ///
	keep(rltv_death_rate_n_1990 famine_q2 famine_q3 famine_q4) ///
	label addtext(region FE, Yes)

reg private_boss1 rltv_death_rate_n_1990 famine_q2 famine_q3 famine_q4 ///
	i.region6 [pw = power_2] if $sample & male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append  bdec(3) sdec(3) ctitle("male") nor2 nocons ///
	addstat(Counties, e(N_clust), Outcome mean, $avg ) ///
	keep(rltv_death_rate_n_1990 famine_q2 famine_q3 famine_q4) ///
	label addtext(region FE, Yes)  

* By urban and rural
use "$final/Census05_sample.dta", clear

reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if ///
	$sample & city == 1 , $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append ctitle("all: Urban region") bdec(3) sdec(3) ///
	nor2 nocons addtext(region FE, Yes) keep(rltv_death_rate_n_1990) ///
	addstat(Counties, e(N_clust), Outcome mean, $avg ) label 
	
reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if ///
	$sample & city == 0 , $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append ctitle("all: Rural region") bdec(3) sdec(3) ///
	nor2 nocons addtext(region FE, Yes) keep(rltv_death_rate_n_1990) ///
	addstat(Counties, e(N_clust), Outcome mean, $avg ) label 
	
reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if ///
	$sample & city == 1 & male==0, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append ctitle("female: Urban region") bdec(3) sdec(3) ///
	nor2 nocons addtext(region FE, Yes) keep(rltv_death_rate_n_1990) ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) label 

reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if ///
	$sample & city == 0 & male==0, $options vce($btopt)	
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append ctitle("female: Rural region") bdec(3) sdec(3) ///
	nor2 nocons addtext(region FE, Yes) keep(rltv_death_rate_n_1990) ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) label 
	
reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if ///
	$sample & city == 1 & male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append ctitle("male: Urban region") bdec(3) sdec(3) ///
	nor2 nocons addtext(region FE, Yes) keep(rltv_death_rate_n_1990) ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) label 

reg private_boss1 rltv_death_rate_n_1990 i.region6 [pw = power_2] if ///
	$sample & city == 0 & male==1, $options vce($btopt)
su private_boss1 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append ctitle("male: Rural region") bdec(3) sdec(3) ///
	nor2 nocons addtext(region FE, Yes) keep(rltv_death_rate_n_1990) ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) label 


********************************************************************************
// Figure 2 and Table S6
********************************************************************************

capture program drop se_program
program define se_program
	global depvar = `2'
	su $depvar if `1'
	global p_mean = r(mean)
	su `3' if `1'
	global death_avg = r(mean) 
	lincom $death_avg * `3' / $p_mean 	
	global est: display %5.3f r(estimate) 
	global se: display %5.3f r(se) 
end

use "$final/Op-cond-cor.dta", clear

* All

global outfile $tables/TableS6_op_cond_all.xls
global btopt bootstrap, force reps(100) seed(1)
gen coef2 = . 
gen se2 = .

preserve

by uid2000: gen dup = _n
keep if dup==1

reg private_n_ttl_ln rltv_death_rate_n_1990 popn_n_ttl_ln i.region6 ///
	[pw = power_2] if mis_n==0, vce($btopt)  	
outreg2 using "$outfile", replace ctitle("All: 1947-61") bdec(3) sdec(3) ///
	nor2 nocons addtext(region FE, Yes) label keep(rltv_death_rate_n_1990 ///
	popn_n_ttl_ln)
	
restore
 
foreach i in 1947 1950 1953 1956 1959  {
	quietly reg private_n_cor_ln rltv_death_rate_n_1990 pred_n_cor_ln i.region6 ///
		[pw = power_2] if cohort == `i' & mis_n==0 , vce($btopt)   	
	se_program e(sample) e(depvar) rltv_death_rate_n_1990
	outreg2 using "$outfile", append  ctitle("All: Cohort `i'") bdec(3) sdec(3) ///
		nor2 nocons addtext(region FE, Yes) label keep(rltv_death_rate_n_1990 ///
		pred_n_cor_ln)
	replace coef2 = $est if cohort == `i' 
	replace se2 =  $se if cohort == `i'
	}
gen upper2 = coef2 + 1.96 * se2
gen lower2 = coef2 - 1.96 * se2 

preserve

bysort group: keep if _n ==1 
keep coef* upper* lower*  cohort 
label var coef2 "Entrepreneur (owner or self-employed)" 
label var upper2 "95% CI"
drop if mi(coef2) 
graph twoway (connected coef cohort , legend(on) lwidth(medthick)) ///
  (connected upper cohort, legend(on) lwidth(medthick)) ///
  (connected lower cohort, msymbol(D) lpattern(dash) lwidth(medthick)) , ///
  scheme(s1mono) xlabel(1947[3]1959, valuelabel labsize(small)) legend(off) ///
  yline(0) ytitle("Regression coeff of predicted cohort loss")
graph export "$figures/Figure2_op_cond_all.png", as(png) replace

restore


* Male

global outfile $tables/TableS6_op_cond_male.xls
drop coef2 se2 upper2 lower2
gen coef2 = . 
gen se2 = .

preserve

by uid2000: gen dup = _n
keep if dup==1

reg private_m_ttl_ln rltv_death_rate_m_1990 popn_m_ttl_ln i.region6 ///
	[pw = power_2] if mis_m==0, vce($btopt)   	
outreg2 using "$outfile", replace ctitle("Male: 1947-61") bdec(3) sdec(3) ///
	nor2 nocons addtext(region FE, Yes) label keep(rltv_death_rate_m_1990 ///
	popn_m_ttl_ln)

restore
 
foreach i in 1947 1950 1953 1956 1959  {
	quietly reg private_m_cor_ln rltv_death_rate_m_1990 pred_m_cor_ln i.region6 ///
		[pw = power_2] if cohort == `i' & mis_m==0 , vce($btopt)   	
	se_program e(sample) e(depvar) rltv_death_rate_m_1990
	outreg2 using "$outfile", append ctitle("Male: Cohort `i'") bdec(3) sdec(3) ///
		nor2 nocons addtext(region FE, Yes) label keep(rltv_death_rate_m_1990 ///
		pred_m_cor_ln)
	replace coef2 = $est if cohort == `i' 
	replace se2 =  $se if cohort == `i'
	}
gen upper2 = coef2 + 1.96 * se2 
gen lower2 = coef2 - 1.96 * se2 

preserve

bysort group: keep if _n ==1 
keep coef* upper* lower*  cohort 
label var coef2 "Entrepreneur (owner or self-employed)" 
label var upper2 "95% CI"
drop if mi(coef2) 
graph twoway (connected coef cohort , legend(on) lwidth(medthick)) ///
  (connected upper cohort, legend(on) lwidth(medthick)) ///
  (connected lower cohort, msymbol(D) lpattern(dash) lwidth(medthick)) , ///
  scheme(s1mono) xlabel(1947[3]1959, valuelabel labsize(small)) legend(off) ///
  yline(0) ytitle("Regression coeff of predicted cohort loss")
graph export "$figures/Figure2_op_cond_male.png", as(png) replace

restore

* Female

global outfile $tables/TableS6_op_cond_female.xls
drop coef2 se2 upper2 lower2
gen coef2 = . 
gen se2 = .

preserve

by uid2000: gen dup = _n
keep if dup==1

reg private_f_ttl_ln rltv_death_rate_f_1990 popn_f_ttl_ln i.region6 ///
	[pw = power_2] if mis_f==0 , vce($btopt)   	
outreg2 using "$outfile", replace ctitle("Female: 1947-61") bdec(3) sdec(3) ///
	nor2 nocons addtext(region FE, Yes) label keep(rltv_death_rate_f_1990 popn_f_ttl_ln)
 
restore

foreach i in 1947 1950 1953 1956 1959  {
	quietly reg private_f_cor_ln rltv_death_rate_f_1990 pred_f_cor_ln ///
	i.region6 [pw = power_2] if cohort == `i' & mis_f==0 , vce($btopt)   	
	se_program e(sample) e(depvar) rltv_death_rate_f_1990
	outreg2 using "$outfile", append  ctitle("Female: Cohort `i'") bdec(3) ///
		sdec(3) nor2 label nocons addtext(region FE, Yes) ///
		keep(rltv_death_rate_f_1990 pred_f_cor_ln)
	replace coef2 = $est if cohort == `i' 
	replace se2 =  $se if cohort == `i'
}
gen upper2 = coef2 + 1.96 * se2 
gen lower2 = coef2 - 1.96 * se2 

preserve

bysort group: keep if _n ==1 
keep coef* upper* lower*  cohort 
label var coef2 "Entrepreneur (owner or self-employed)" 
label var upper2 "95% CI"
drop if mi(coef2) 
graph twoway (connected coef cohort , legend(on) lwidth(medthick)) ///
  (connected upper cohort, legend(on) lwidth(medthick)) ///
  (connected lower cohort, msymbol(D) lpattern(dash) lwidth(medthick)) , ///
  scheme(s1mono) xlabel(1947[3]1959, valuelabel labsize(small)) legend(off) ///
  yline(0) ytitle("Regression coeff of predicted cohort loss")
graph export "$figures/Figure2_op_cond_female.png", as(png) replace

restore


	
*********************
*** Table S7 Risk ***
*********************

use "$final/cfps10_sample.dta", clear
append using "$final/cgss101213_sample.dta"
append using "$final/chfs11_sample.dta"
keep stock investment countyid survey wave rltv_death_rate_n_1990 birthyr private_boss

label var stock "Share investment"
label var investment "Financial investment"
label var private_boss "Owner"

drop if birthyr > 1961 

global outfile $tables/TableS7_Risk.xls
global options cluster(countyid) vce(bootstrap, force reps(100) seed(1))
global sample !mi(stock) & !mi(investment) & !mi(private_boss) // &wave!=2011

quietly xi: reg stock rltv_death_rate_n_1990 i.survey i.wave if $sample, $options
su stock if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", replace bdec(3) sdec(3) nor2 keep(rltv_death_rate_n_1990) ///
	addstat(Counties, e(N_clust), Outcome mean, $avg) ///
	addtext(Individual controls, No, Survey fixed effects, Yes, Wave fixed effects, Yes) ///
	addnote(Robust s.e. clustered at county level) label ctitle("OLS: Share investment")

foreach i in investment private_boss {
	local dv: var label `i'
	quietly xi: reg `i' rltv_death_rate_n_1990 i.survey i.wave if $sample  , $options 
	su `i' if e(sample)
	global avg : display %5.3f r(mean)
	outreg2 using "$outfile", append bdec(3) sdec(3) nor2 keep(rltv_death_rate_n_1990) ///
		addstat(Counties, e(N_clust), Outcome mean, $avg) ctitle("OLS: `dv'") ///
		addtext(Individual controls, No, Survey fixed effects, Yes, Wave fixed effects, Yes) label
}


********************************
*** Table S8 Time preference ***
********************************

use "$final/chfs11_sample.dta",clear
keep if birthyr<1962

global iv="rltv_death_rate_n_1990"
global indep="time_preference"
global ind="age minority primary highschool college urban health"
global weight="[pweight=swgt]"
global clu="vce(bootstrap, force rep(100) seed(1)) cluster(cityid)"

egen mis2=rowmiss($iv $ind $indep)
gen samp2=.

replace samp2=(mis2==0&respond==1)

global con="male $ind"

foreach dep of varlist $indep $iv {
qui sum `dep' if samp2==1,detail
scalar ave_`dep'=round(r(mean),.001)
}

//both genders

reg $indep $iv $con $weight if samp2==1, $clu
estadd local profe "Yes"
estadd local birth "Yes"
estadd local con "Yes"
estadd scalar cou=e(N_clust)
estadd scalar ave=ave_$indep
est store time

forvalue i=0(1)1{
replace samp2=(mis2==0&respond==1&male==`i')
global con="$ind $fe"

foreach dep of varlist $indep $iv{
qui sum `dep' if samp2==1,detail
scalar ave_`dep'=round(r(mean),.001)
}
 reg $indep $iv $con $weight if samp2==1, $clu
estadd local profe "Yes"
estadd local birth "Yes"
estadd local con "Yes"
estadd scalar cou=e(N_clust)
estadd scalar ave=ave_$indep
est store time_`i'

}

esttab time time_0 time_1, ///
keep($iv )  order($iv )  star(* 0.10 ** 0.05 *** 0.01) stats(con N cou ave, ///
label("Individual controls" "Observations" "# counties" "Mean") fmt(0 0 0 3 3 3)) 

esttab time time_0 time_1   ///
using "$tables/TableS8_time_preference.csv", keep($iv) order($iv) replace se b(3) ///
mtitles("Time preference" "Time preference (Male)" "Time preference (Female)") ///
depvars star(* 0.10 ** 0.05 *** 0.01) nogaps label title("") stats(con N cou ave, ///
label("Individual controls" "Observations" "# counties" "Mean") fmt(0 0 0 3 3 3))

*****************************
*** Table S9 Social norms ***
*****************************
use "$final/chfs13_sample.dta",clear
keep if birthyr<1962

global iv="rltv_death_rate_n_1990"
global dep="busi_owner"
global indep="risk_loving"
global ind="age minority primary highschool college urban health"
global weight="[pweight=swgt]"
global clu="vce(bootstrap, force rep(100) seed(1)) cluster(cityid)"

egen mis2=rowmiss($dep $iv $ind $indep)
gen samp2=.

replace samp2=(mis2==0&respond==1)

global con="$ind"

forvalue i=0(1)1{
preserve
keep if (mis2==0&respond==1&male==`i')

qui sum $dep if hhshare_f==1,detail
scalar ave =round(r(mean),.001)

 reg $dep $iv $con $weight if hhshare_f==1, $clu
estadd local profe "Yes"
estadd local birth "Yes"
estadd local con "Yes"
estadd scalar cou=e(N_clust)
estadd scalar ave=ave
est store hhshare_fh1_male`i'

qui sum  $dep if hhshare_f==0,detail
scalar ave=round(r(mean),.001)
 reg $dep $iv  $con $weight if hhshare_f==0, $clu
estadd local profe "Yes"
estadd local birth "Yes"
estadd local con "Yes"
estadd scalar cou=e(N_clust)
estadd scalar ave=ave
est store hhshare_fh0_male`i'

restore
}
esttab  hhshare_fh0_male0 hhshare_fh1_male0  hhshare_fh0_male1 hhshare_fh1_male1  , keep($iv) ///
star(* 0.10 ** 0.05 *** 0.01) stats(con N cou ave, ///
label("Individual controls" "Observations" "# counties" "Mean") fmt(0 0 0 3 3 3))  se(3)


esttab hhshare_fh0_male0 hhshare_fh1_male0 hhshare_fh0_male1 hhshare_fh1_male1    ///
using "$tables/TableS9_social_norm.csv", keep($iv hhshare_f rltv_hhshare_f) ///
order($iv hhshare_f rltv_hhshare_f) replace t b(3) se(3) ///
mtitles("Below median (Female) " "Above median (Female) " "Below median (Male) " "Above median (Male) " ) ///
depvars star(* 0.10 ** 0.05 *** 0.01) nogaps label title("") stats(con N cou ave, ///
label("Individual controls" "Observations" "# counties" "Mean") fmt(0 0 0 3 3 3))


********************************
** Table S10 Self-confidence ***
********************************
use "$final/cgss11_sample.dta", clear

global options cluster(countyid) vce(bootstrap, force reps(100) seed(1))
global outfile $tables/TableS10_Self_confidence.xls 

* all

oprobit a43g rltv_death_rate_n_1990, $options  
su a43g if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", replace bdec(3) sdec(3) addstat(Counties, ///
	e(N_clust), Outcome mean, $avg) label ctitle("all: Power")

foreach i in d17_d d17_e d31a d31b {
	local dv: var label `i'
	oprobit `i' rltv_death_rate_n_1990, $options
	su `i' if e(sample)
	global avg : display %5.3f r(mean)
	outreg2 using "$outfile", append bdec(3) sdec(3) addstat(Counties, ///
		e(N_clust), Outcome mean, $avg) label ctitle("all: `dv'")
}

* female
foreach i in a43g d17_d d17_e d31a d31b {
	local dv: var label `i'
	oprobit `i' rltv_death_rate_n_1990 if male==0, $options
	su `i' if e(sample)
	global avg : display %5.3f r(mean)
	outreg2  using "$outfile", append bdec(3) sdec(3) addstat(Counties, ///
		e(N_clust), Outcome mean, $avg) label ctitle("female: `dv'")
}

* male
foreach i in a43g d17_d d17_e d31a d31b {
	local dv: var label `i'
	oprobit `i' rltv_death_rate_n_1990 if male==1, $options
	su `i' if e(sample)
	global avg : display %5.3f r(mean)
	outreg2  using "$outfile", append bdec(3) sdec(3) addstat(Counties, ///
		e(N_clust), Outcome mean, $avg) label ctitle("male: `dv'")
}

*********************************************
*** Table S11 tenacity and resilience (1) ***
*********************************************
use "$final/cgss11_sample.dta", clear
append using "$final/cgss08_sample.dta"

keep birthyr countyid resil3 resil5 rltv_death_rate_n_1990 wave male
drop if birthyr > 1961 

global outfile $tables/TableS11_tenacity_resilience_1.xls
global options cluster(countyid) vce(bootstrap, force reps(100) seed(1))

* all

local dv: var label resil3 
oprobit resil3 rltv_death_rate_n_1990 i.wave , $options
su resil3 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", replace bdec(3) sdec(3) addstat(Counties, e(N_clust), ///
	Outcome mean, $avg) label ctitle("all: `dv'")

local dv: var label resil5
oprobit resil5 rltv_death_rate_n_1990 i.wave , $options
su resil5 if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) addstat(Counties, e(N_clust), ///
	Outcome mean, $avg) label ctitle("all: `dv'")

* female

foreach i in resil3 resil5 {
	local dv: var label `i'
	oprobit `i' rltv_death_rate_n_1990 i.wave if male==0, $options
	su `i' if e(sample)
	global avg : display %5.3f r(mean)
	outreg2 using "$outfile", append bdec(3) sdec(3) addstat(Counties, ///
		e(N_clust), Outcome mean, $avg) label ctitle("female: `dv'")
}

* male

foreach i in resil3 resil5 {
	local dv: var label `i'
	oprobit `i' rltv_death_rate_n_1990 i.wave if male==1, $options
	su `i' if e(sample)
	global avg : display %5.3f r(mean)
	outreg2 using "$outfile", append bdec(3) sdec(3) addstat(Counties, ///
		e(N_clust), Outcome mean, $avg) label ctitle("male: `dv'")
}

*********************************************
*** Table S11 tenacity and resilience (2) ***
*********************************************

use "$final/cgss08_sample.dta", clear
keep countyid male health send_down famine_sdown rltv_death_rate_n_1990 wave birthyr

drop if birthyr > 1961 
global outfile $tables/TableS11_tenacity_resilience_2.xls
global options cluster(countyid) vce(bootstrap, force reps(100) seed(1))
global sample !mi(rltv_death_rate_n_1990) & !mi(send_down)

* all

local dv: var label health
oprobit health rltv_death_rate_n_1990 if $sample, $options
su health if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", replace bdec(3) sdec(3) addstat(Counties, e(N_clust), ///
	Outcome mean, $avg) label ctitle("all: `dv'")

local dv: var label health
oprobit health send_down if $sample, $options
su health if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) addstat(Counties, e(N_clust), ///
	Outcome mean, $avg) label ctitle("all: `dv'")
	
local dv: var label health
oprobit health rltv_death_rate_n_1990 send_down famine_sdown if $sample , $options
su health if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) addstat(Counties, e(N_clust), ///
	Outcome mean, $avg) label ctitle("all: `dv'")
	
* female

local dv: var label health
oprobit health rltv_death_rate_n_1990 if $sample & male == 0, $options
su health if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) addstat(Counties, e(N_clust), ///
	Outcome mean, $avg) label ctitle("female: `dv'")

local dv: var label health
oprobit health send_down if $sample & male == 0, $options
su health if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) addstat(Counties, e(N_clust), ///
	Outcome mean, $avg) label ctitle("female: `dv'")
	
local dv: var label health
oprobit health rltv_death_rate_n_1990 send_down famine_sdown if $sample & male == 0, $options
su health if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) addstat(Counties, e(N_clust), ///
	Outcome mean, $avg) label ctitle("female: `dv'")
	
* male

local dv: var label health
oprobit health rltv_death_rate_n_1990 if $sample & male == 1, $options
su health if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) addstat(Counties, e(N_clust), ///
	Outcome mean, $avg) label ctitle("male: `dv'")

local dv: var label health
oprobit health send_down if $sample & male == 1, $options
su health if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) addstat(Counties, e(N_clust), ///
	Outcome mean, $avg) label ctitle("male: `dv'")
	
local dv: var label health
oprobit health rltv_death_rate_n_1990 send_down famine_sdown if $sample & male == 1, $options
su health if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) addstat(Counties, e(N_clust), ///
	Outcome mean, $avg) label ctitle("male: `dv'")

*****************************
*** Table S12 opportunism ***
*****************************

use "$final/cgss08_sample".dta, replace
keep countyid guanxi rltv_death_rate_n_1990 male birthyr
drop if birthyr > 1961

global outfile $tables/TableS12_opportunism_1.xls
global options cluster(countyid) vce(bootstrap, force reps(100) seed(1))

local dv: var label guanxi
reg guanxi rltv_death_rate_n_1990, $options first
su guanxi if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", replace bdec(3) sdec(3) addstat(Counties, ///
	e(N_clust), Outcome mean, $avg) label ctitle("all: `dv'")

reg guanxi rltv_death_rate_n_1990 if male==0, $options first
su guanxi if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) addstat(Counties, ///
	e(N_clust), Outcome mean, $avg) label ctitle("female: `dv'")

reg guanxi rltv_death_rate_n_1990 if male==1, $options first
su guanxi if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) addstat(Counties, ///
	e(N_clust), Outcome mean, $avg) label ctitle("male: `dv'")


use "$final/cfps10_sample.dta",replace 
keep corruption rltv_death_rate_n_1990 countyid male birthyr
drop if birthyr > 1961

global outfile $tables/TableS12_opportunism_2.xls
global options cluster(countyid) vce(bootstrap, force reps(100) seed(1))

local dv: var label corruption
oprobit corruption rltv_death_rate_n_1990, $options
su corruption if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) addstat(Counties, ///
	e(N_clust), Outcome mean, $avg) label ctitle("all: `dv'")

oprobit corruption rltv_death_rate_n_1990 if male==0, $options
su corruption if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) addstat(Counties, ///
	e(N_clust), Outcome mean, $avg) label ctitle("female: `dv'")

oprobit corruption rltv_death_rate_n_1990 if male==1, $options
su corruption if e(sample)
global avg : display %5.3f r(mean)
outreg2 using "$outfile", append bdec(3) sdec(3) addstat(Counties, ///
	e(N_clust), Outcome mean, $avg) label ctitle("male: `dv'")


* Police
use "$final/Census00_sample.dta",clear
global outfile $tables/TableS12_opportunism_3.xls
global sample police > 0
global options cluster(stationid) vce(bootstrap, force reps(100) seed(1))

reg police_ln rltv_death_rate_n_1990 popn_ln if $sample , $options	
outreg2 using "$outfile", append bdec(3) sdec(3) addstat(Counties, ///
	e(N_clust), Outcome mean, $p_mean) label
